﻿using AuditSample.Model;
using System;
using System.Activities.Tracking;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AuditSample.Persistence
{
    public class StateTrackingParticipant : TrackingParticipant
    {

        public StateTrackingDTO State { get; set; }

        protected override void Track(TrackingRecord record, TimeSpan timeout)
        {
            if (record != null)
            {
                if (record is CustomTrackingRecord)
                {
                    var customRecord = (CustomTrackingRecord)record;
                    if (customRecord.Name.Equals("StateTracking", StringComparison.InvariantCultureIgnoreCase))
                    {
                        State = new StateTrackingDTO();
                        State.AuditRole = customRecord.Data.GetString("AuditRole");
                        State.Auditer = customRecord.Data.GetString("Auditer");
                        State.State = customRecord.Data.GetString("State");
                        State.UpdatedDate = customRecord.Data.GetDate("Date");
                        State.RecordNumber = customRecord.RecordNumber.ToString();
                    }
                }
            }
        }
    }
}
